﻿using System;

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;


namespace Qetza.TeamFoundation.WorkItemQuery.Admin
{
    /// <summary>
    ///  Contains TFS utility methods.
    /// </summary>
    internal static class TfsUtility
    {
        #region Methods

        /// <summary>
        /// Returns a instance of the work item store.
        /// </summary>
        /// <param name="tfsName">
        /// The TFS server name.
        /// </param>
        /// <param name="noPrompt">
        /// <b>true</b> not to prompt for credential; otherwise <b>false</b>.
        /// </param>
        /// <returns>
        /// An instance of <see cref="WorkItemStore"/>.
        /// </returns>
        public static WorkItemStore GetWorkItemStore(string tfsName, bool noPrompt)
        {
            ICredentialsProvider provider = null;
            if (!noPrompt)
            {
                provider = new UICredentialsProvider();
            }

            var tfs = new TeamFoundationServer(tfsName, provider);
            tfs.EnsureAuthenticated();

            return (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
        }

        #endregion
    }
}
